﻿using Presenters.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Subject
{
    /// <summary>
    /// Lógica de interacción para NewSubject.xaml
    /// </summary>
    public partial class SubjectSolution : Window, INewSubject
    {
        NewSubjectPresenter presenter;
        private string Message;
        Model.Subject modify = new Model.Subject() { code = -1 };

        public SubjectSolution()
        {
            InitializeComponent();
            this.ComboBox_status.SelectedIndex = 0;
            presenter = new NewSubjectPresenter(this);
        }


        //Modify 
        public SubjectSolution(Model.Subject changeSubject)
        {
            InitializeComponent();
            presenter = new NewSubjectPresenter(this);
            this.Title = "Modificar Materia";
            this.Button_CreateSubject.Visibility = Visibility.Hidden;
            this.Button_ModifySubject.Visibility = Visibility.Visible;
            this.modify = changeSubject;

            fillAllCampus();
            enableEditCampus();
        }


        //Watch info
        public SubjectSolution(Model.Subject changeSubject, string infoButton)
        {
            InitializeComponent();
            presenter = new NewSubjectPresenter(this);
            this.Title = "Modificar Materia";
            this.Button_CreateSubject.Visibility = Visibility.Hidden;
            this.Button_Cancel.Content = infoButton;
            this.modify = changeSubject;

            fillAllCampus();
        }


        public void enableEditCampus()
        {
            this.TextBox_acronym.IsEnabled = false;
            this.TextBox_description.IsEnabled = true;
            this.TextBox_credits.IsEnabled = true;
            this.TextBox_nameSubject.IsEnabled = true;
            this.ComboBox_status.IsEnabled = true;
        }

        public void fillAllCampus()
        {
            this.TextBlock_code.Text = modify.code.ToString();
            this.TextBox_acronym.Text = modify.acronym;
            this.TextBox_credits.Text = modify.credits.ToString();
            this.TextBox_description.Text = modify.description;
            this.TextBox_nameSubject.Text = modify.nameSubject;
            this.ComboBox_status.SelectedValue = modify.status;
        }


        public string nameSubject
        {
            get { return TextBox_nameSubject.Text; }
        }
        public int credits
        {
            get { return Convert.ToInt32(TextBox_credits.Text); }
        }
        public String acronym
        {
            get { return TextBox_acronym.Text; }
        }
        public char status
        {
            get { return Convert.ToChar(ComboBox_status.SelectedValue.ToString()); }
        }
        public string description
        {
            get { return TextBox_description.Text; }
        }
        public string message
        {
            set { Message = value; }
        }
        public long code
        {
            get { return (modify.code); }
        }

        private void Button_CreateSubject_Click(object sender, RoutedEventArgs e)
        {
            presenter.SubmitNewSubject();
            MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        private void Button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void TextBox_creditsValidation(object sender, TextChangedEventArgs e)
        {
            if (!String.IsNullOrEmpty(this.TextBox_credits.Text))
            {
                if (presenter.SubmitValidationCreditsText() == false)
                {
                    MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);
                    this.TextBox_credits.Text = "";
                }
            }
        }

        private void Button_Click_ModififySubject(object sender, RoutedEventArgs e)
        {
            presenter.SubmitModifySubject();
            MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }
}
